<template>
  <div class="login-container">
      <el-form :model="user" ref="refForm" :rules="Loginrules" class="login-form">
        <h2 class="login-title">扶贫助农平台</h2>
        <el-form-item label="用户名" prop="username">
            <el-input v-model="user.username" type="text" placeholder="请输入用户名"></el-input>

        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="user.password" type="password" placeholder="请输入密码"></el-input>
            
        </el-form-item>
        <el-form-item style="text-align:center">
           <el-button type="primary" @click="submitForm('refForm')">登录</el-button>
            <el-button type="info" @click="resetForm('refForm')">重置</el-button>
        </el-form-item>
      </el-form>
     
  </div>
</template>
<script>
export default {
    data () {
        return {
            user:{
                username:'',
                password:''            
                },
                Loginrules:{
                username:[
                    // 当鼠标失去焦点时验证，必填
                    {required:true,message:'用户名不能为空', trigger: 'blur'},
                    {min: 3, max: 10, message: '用户名3-10位', trigger: 'blur'}
                ],
                password:[
                    {required:true,message:'密码不能为空', trigger: 'blur'}
                   
                ]
            } 
        }
    },
    methods:{
        submitForm(formName){
            // window.console.log(formName);
             this.$refs[formName].validate((valid) => {
        if (valid) {
            // window.console.log(valid);
            if(this.user.username=="admin"&&this.user.password=="123456"){
              this.$message.success('登录成功');
                    // 跳转主页
               this.$router.push('/main');
            }else{
                this.$message.error('用户名或密码不正确');
            }
            
        } else {
            window.console.log('error submit!!');
            return false;
        }
        });

        },
        resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
}
</script>
<style scoped>
.login-container{
    position: absolute;
    width: 100%;
    height: 100%;
    background-color:paleturquoise;
}
.login-form{
    width: 350px;
    margin: 100px auto;
    background-color: palegreen;
    border-radius: 20px;
    padding: 20px;
    text-align: center;

}
.login-title{
    text-align: center;
}
</style>